package com.gjy.util.sb.use;

import com.gjy.util.sb.aop.annotation.LogRecord;
import com.gjy.util.sb.aop.annotation.PreCheckId;
import com.gjy.util.sb.aop.dto.DataPermission;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.time.LocalDate;
import java.util.concurrent.TimeUnit;

/**
 * @author 宫静雨
 * @version 1.0
 * @since 2023-10-23 10:49:43
 */
@Service
public class AopUse {

    private static final Logger log = LoggerFactory.getLogger(AopUse.class);

    @Resource
    private DataTT dataTT;

    public void testDataPermission() {
        DataPermission permission = DataPermission.builder().userId("1").build();
        dataTT.dataPermission(permission);
    }

    @PreCheckId(userId = "#a")
    public Object checkId(Long a, String t2) {
        return "Hello AOP " + a + "\tt2 = " + t2;
    }

    @LogRecord
    public Object log1(DataPermission dataPermission) {
        try {
            TimeUnit.SECONDS.sleep(2);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
        return LocalDate.now();
    }

    @LogRecord(module = "A", type = "1", desc = "aop-use.log2")
    public void log2(String b) {
        try {
            int a = 1 / 0;
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
}
